#!/bin/bash

echo 'build_path:=../../build/' > Makefile
echo 'CC:=g++' >> Makefile
echo 'AR:=ar' >> Makefile

target=$(pwd)
target=${target##*/}.a
echo 'target:='${target} >> Makefile

objects="$(ls *.cpp)"
objects=${objects//cpp/o}
echo 'objects:='${objects} >> Makefile

echo '$(build_path)$(target): $(objects)' >> Makefile
echo '	$(AR) cr $@ $^' >> Makefile

declare -a sources
sources=($(ls *.cpp))
for var in ${sources[@]}; do
	rely=$(g++ -MM ${var})
	rely=${rely//'\'/}
	echo ${rely} >> Makefile
	echo '	$(CC) -c '${var} >> Makefile
done

echo '.PHONY: clean' >> Makefile
echo 'clean:' >> Makefile
echo '	rm -f $(build_path)$(target) *.o' >> Makefile

